# -*- coding: utf-8 -*-

from src.com.bsjs.util.base_util import BaserUtil
from src.com.bsjs.util.html_util import HtmlClient
from src.com.bsjs.util.http_util import HttpClient
from src.com.bsjs.util.redis_util import RedisUtil
from src.com.bsjs.util.selenium_util import SeleniumClient
from src.com.bsjs.util.sql_util import MySQLUtils


class Spider:
    def __init__(self):
        self.http_client = HttpClient()
        self.redis_client = RedisUtil()
        self.base_client = BaserUtil()
        self.mysql_client = MySQLUtils()
        self.html_client = HtmlClient()
        self.headers = {
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36"
        }
        self.selenium_client = SeleniumClient(load_selenium=True)
        self.url='https://www.hsbianma.com/'

    def load_html(self):
        index_html=self.redis_client.get_value(self.url)
        if index_html!=None and len(index_html)>0:
            return index_html
        self.selenium_client.open_url(URL=self.url,fast_falg=False)
        index_html=self.selenium_client.source_code()
        self.redis_client.set_value(self.url,index_html)
        return index_html


def main():
    this = Spider()
    index_html=this.load_html()
    print(index_html)


if __name__ == '__main__':
    main()